package com.ktjy.test;

import com.ktjy.entity.Host;
import com.ktjy.entity.Pet;
import com.ktjy.service.PetService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    @Test
    public void test1() {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        Pet pet = (Pet) context.getBean("pet1");
        pet.introduce();
    }
    @Test
    public void test2() {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        Pet pet = (Pet) context.getBean("pet2");
        pet.introduce();
    }
    @Test
    public void test3() {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        Pet pet = (Pet) context.getBean("pet3");
        pet.introduce();
    }
    @Test
    public void test4() {
        ApplicationContext context =
                new ClassPathXmlApplicationContext("classpath:applicationContext.xml");

        Host host = (Host) context.getBean("host1");
        System.out.println(host.getHost() + "," + host.getPet().getName() + "," + host.getPet().getAge());
    }
    @Test
    public void test5(){
        ApplicationContext context = new
                ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        Pet pet=(Pet) context.getBean("pet1");
        PetService petService=(PetService) context.getBean("petService");
        petService.addPet(pet);
    }
}
